package com.example.message.service.impl;

import com.example.message.dao.UserDao;
import com.example.message.dao.entity.UserEntity;
import com.example.message.dao.mapper.UserMapper;
import com.example.message.pojo.User;
import com.example.message.pojo.UserInfo;
import com.example.message.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    UserMapper userMapper;

    @Override
    public User Login(String userName, String password) {
        UserEntity userEntity = userMapper.selectByPrimaryKey(1L);
        return userDao.login(userName, password);
    }

    @Override
    public boolean register(User user) {
        return userDao.register(user);
    }

    @Override
    public boolean updatePassword(int userId, String password) {
        return userDao.updatePassword(userId, password);
    }
    @Override
    public  boolean updateMessage(UserInfo userInfo){
        return userDao.updateMessage(userInfo);
    }

    @Override
    public List<User> selectByUserName(String userName) {
        return userDao.selectByUserName(userName);
    }

    @Override
    public boolean loginMessage(User user) {
        User loginUser =  userDao.loginHistoryByUserId(user.getId());
        if (loginUser == null) {
            return userDao.loginMessage(user);
        } else {
//            return UserDao.updateLoginMessage(user);
        }
        return userDao.loginMessage(user);
    }
}
